<?php if (!defined('TL_ROOT')) die('You can not access this file directly!');

class setDropDown extends Controller
{
	public function __construct()
	{
		parent::__construct();		
	}
	
	public function run()
	{
		$divId	= "advanced_search_ft";
		$formH3 = "ADVANCED SEARCH";
		
		$str  = "<div id=\"$divId\">\n";
		$str .= "<form method=\"get\" action=\"search_result.html\">\n";
		$str .= "<h3>$formH3</h3>\n";
		$str .= $this->getCategory();
		$str .= $this->getBrand();
		$str .= $this->getColour();
		$str .= $this->getSize();
		$str .= $this->setPrice();
		$str .= "<input type=\"hidden\" name=\"form_filter\" value=\"action\">\n";
		$str .= "</form>\n";
		$str .= "</div>\n";
		
		echo $str;
	}
	
	public function getCategory()
	{
		$nav = array();
		$this->import('Database');
		$objRd = $this->Database->execute("SELECT tl_taxonomy.id AS id, pid, alias, name FROM tl_taxonomy Order by sorting asc");
		while ($objRd->next())
		{
			$nav[$objRd->pid][] = array('id'=>$objRd->id, 'name'=>$objRd->name);
		}
		
		$str  = "<select class=\"select_category\" name=\"ads_category\" onchange=\"form.submit()\">\n";
		$str .= "<option value=\"all\">CHOOSE CATEGORY</option>\n";
		
		for($i=0;$i<count($nav[0]);$i++){
			$id   = $nav[0][$i]['id'];
			$name = $nav[0][$i]['name'];

			$str .= "<option value=\"$id\">$name</option>\n";
			
			if($nav[$id]!=Null){
				for($j=0;$j<count($nav[$id]);$j++){
					$sid  	= $nav[$id][$j]['id'];
					$sname  = $nav[$id][$j]['name'];				
					$str .= "<option value=\"$sid\">--$sname</option>\n";
				}
			}
		}
		
		$str .= "</select>\n";
		
		return $str;
	}
	
	public function getBrand()
	{
		$this->import('Database');
		
		$objRd = $this->Database->execute("SELECT catalog_brand.id AS id, brand FROM catalog_brand Order by sorting asc");
		
		$str  = "<select class=\"select_brand\" name=\"ads_brand\" onchange=\"form.submit()\">\n";
		$str .= "<option value=\"all\">BRAND</option>\n";

		while ($objRd->next())
		{
			$str .= "<option value=\"$objRd->id\">$objRd->brand</option>\n";
		}
		
		$str .= "</select>\n";
		
		return $str;
	}	
	
	public function getColour()
	{
		$this->import('Database');
		
		$objRd = $this->Database->execute("SELECT catalog_colour.id AS id, title FROM catalog_colour Order by sorting asc");
		
		$str  = "<select class=\"select_colour\" name=\"ads_colour\" onchange=\"form.submit()\">\n";
		$str .= "<option value=\"all\">COLOUR</option>\n";

		while ($objRd->next())
		{
			$str .= "<option value=\"$objRd->id\">$objRd->title</option>\n";
		}
		
		$str .= "</select>\n";
		
		return $str;
	}	
	
	public function getSize()
	{
		$this->import('Database');
		
		$objRd = $this->Database->execute("SELECT catalog_size.id AS id, size FROM catalog_size Order by sorting asc");
		
		$str  = "<select class=\"select_size\" name=\"ads_size\" onchange=\"form.submit()\">\n";
		$str .= "<option value=\"all\">SIZE</option>\n";

		while ($objRd->next())
		{
			$str .= "<option value=\"$objRd->id\">$objRd->size</option>\n";
		}
		
		$str .= "</select>\n";
		
		return $str;
	}	

	public function setPrice()
	{
		$priceList = array(
			array("0","<=50"),
			array("1","50-200"),
			array("2","201-1000")
		);
		
		$str  = "<select class=\"select_price\" name=\"ads_price\" onchange=\"form.submit()\">\n";
		$str .= "<option value=\"all\">PRICE</option>\n";
		
		for($i=0;$i<count($priceList);$i++){
			$str .= "<option value=\"".$priceList[$i][0]."\">".$priceList[$i][1]."</option>\n";
		}
		
		$str .= "</select>\n";
		
		return $str;
	}	
	
}


$objGetRd = new setDropDown();
$objGetRd->run();

?>